#include "TLogger.h"

#include <log4qt/fileappender.h>
#include <log4qt/ttcclayout.h>

TLogger::TLogger(QString filename)
{
    this->logger()->removeAllAppenders();
    Log4Qt::FileAppender *appender = new Log4Qt::FileAppender();
    appender->setName("FileAppender");
    appender->setFile(filename);
    Log4Qt::TTCCLayout *layout = new Log4Qt::TTCCLayout(Log4Qt::TTCCLayout::ISO8601);
    appender->setLayout(layout);
    appender->activateOptions();
    this->logger()->addAppender(appender);
}

TLogger::~TLogger()
{

}

void TLogger::error(const QString &message)
{
    this->logger()->error(message);
}

void TLogger::fatal(const QString &message)
{
    QString str = message;
    str.replace("utf-8", "utf88");
    this->logger()->fatal(str);
}

void TLogger::info(const QString &message)
{
    QString str = message;
    str.replace("utf-8", "utf88");
    this->logger()->info(str);
}

void TLogger::trace(const QString &message)
{
    QString str = message;
    str.replace("utf-8", "utf88");
    this->logger()->trace(str);
}

void TLogger::debug(const QString &message)
{
    QString str = message;
    str.replace("utf-8", "utf88");
    this->logger()->debug(str);
}

void TLogger::warn(const QString &message)
{
    QString str = message;
    str.replace("utf-8", "utf88");
    this->logger()->warn(str);
}

